package ${package!}.service;

import ${package!}.entity.${table.name!};
import ${package!}.mapper.${table.name!}Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

<@m.copyright/>
@Service("${table.name?uncap_first}Service")
public class ${table.name}Service {
    @Resource
    private ${table.name}Mapper ${table.name?uncap_first}Mapper;

    /**
     * 根据id取得数据
     * @param id id
     * @return 实例对象
     */
    public ${table.name} getById(Integer id) {
        return ${table.name?uncap_first}Mapper.getById(id);
    }

    /**
     * 条件查询
     * @param ${table.name?uncap_first} 实例对象
     * @return 对象列表
     */
    public List<${table.name}> query(${table.name} ${table.name?uncap_first}) {
        return ${table.name?uncap_first}Mapper.query(${table.name?uncap_first});
    }		

    /**
     * 分页条件查询
     * @param ${table.name?uncap_first} 实例对象
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    public List<${table.name}> page(${table.name} ${table.name?uncap_first}, int offset, int limit) {
        return ${table.name?uncap_first}Mapper.page(${table.name?uncap_first}, offset, limit);
    }

    /**
     * 新增一条数据
     * @param ${table.name?uncap_first} 实例对象
     * @return 实例对象
     */
    public ${table.name} insert(${table.name} ${table.name?uncap_first}) {
        ${table.name?uncap_first}Mapper.insert(${table.name?uncap_first});
        return ${table.name?uncap_first};
    }

    /**
     * 根据id修改数据
     * @param ${table.name?uncap_first} 实例对象
     * @return 实例对象
     */
    public ${table.name} update(${table.name} ${table.name?uncap_first}) {
        ${table.name?uncap_first}Mapper.update(${table.name?uncap_first});
        return getById(${table.name?uncap_first}.getId());
    }

    /**
     * 通过id删除数据
     * @param id id
     * @return 是否成功
     */
    public boolean deleteById(Integer id) {
        return ${table.name?uncap_first}Mapper.deleteById(id) > 0;
    }
}